/*
 * Toedo
 * Copyright (C) 2009-2010 J. Devauchelle and contributors.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * version 3 as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

package org.toedo.gui.wizards.newtask;

import org.eclipse.jface.wizard.Wizard;
import org.toedo.controllers.DataController;
import org.toedo.gui.actions.OpenTaskAction;
import org.toedo.logging.Log;
import org.toedo.model.Task;

public class NewTaskWizard extends Wizard {

	private boolean mOpenTask;
	private NewTaskIntroPage mIntroPage;
	
	public NewTaskWizard(boolean openTask) {
		super();
		setNeedsProgressMonitor(true);
		mOpenTask = openTask;
	}
	
	public void addPages() {
		mIntroPage = new NewTaskIntroPage();
		addPage(mIntroPage);
	}

	@Override
	public boolean performFinish() {
		
		Task newTask = DataController.getInstance().getProject().addTask(mIntroPage.getTaskTitle(),
				mIntroPage.getContent(),
				mIntroPage.getStartDate(),
				mIntroPage.getDueDate(),
				mIntroPage.getTaskPriority());
		
		Log.getInstance(NewTaskWizard.class).debug(String.format("Task created: %s (%s)", newTask.getTitle(), newTask.getId())); //$NON-NLS-1$
	
		if ((mOpenTask) &&
				(newTask != null)) {
			new OpenTaskAction(newTask).run();
		}
		
		return true;
	}
	
}
